import _request from "./_request";
import {Message} from "element-ui";

let _call = {

    //类型
    tag: function (callback) {
        let data = {};
        let params = _request._params('Common', 'tag', data);
        _request._post(params, function (response) {
            if (response.code !== _request.success)
            {
                Message.info(response.info);
                return;
            }
            //回调数据
            if (typeof callback === 'function') {
                callback(response.data)
            }
        }, 0)
    },

    //发送短信
    send_single_sms: function(id, tid, sms, callback){

        let data = {};
        data.id = id
        data.tid = tid
        data.sms = sms
        let params = _request._params('Common', 'sms', data);
        _request._post(params, function (response) {
            if (response.code !== _request.success)
            {
                Message.info(response.info);
                return;
            }

            Message.info('发送成功');
            //回调数据
            if (typeof callback === 'function') {
                callback(response.data)
            }
        })
    },

    //确认发送
    confirm_send_sms: function (that) {
        that.$confirm("您确定要发送吗？")
            .then((_) => {
                let id = that.current_id;
                let tid = that.tid;
                let sms = that.tag_form.sms;

                //接口

                let callback = function (data) {
                    that.select_page();
                };

                _call.send_single_sms(id, tid, sms, callback);
            })
            .catch((_) => {});
    }

};

export default _call
